package com.hdphone.zljutils.impl;

import android.graphics.Color;
import android.text.TextUtils;

import com.hdphone.zljutils.inter.IColorUtil;

/**
 * @author sq
 * @date 2020/10/20
 * @describe
 */
public class ColorUtilImpl implements IColorUtil {

    @Override
    public int getColor(String colorStr) {
        int color = Color.WHITE;
        try {
            if (colorStr != null && !colorStr.startsWith("#")) {
                colorStr = "#" + colorStr;
            }
            color = Color.parseColor(colorStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return color;
    }

    @Override
    public int getColor(String colorStr, String defaultColor) {
        int color = Color.WHITE;
        try {
            if (TextUtils.isEmpty(colorStr) && !TextUtils.isEmpty(defaultColor)) {
                color = Color.parseColor(defaultColor);
            } else {
                if (colorStr != null && !colorStr.startsWith("#")) {
                    colorStr = "#" + colorStr;
                }
                color = Color.parseColor(colorStr);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return color;
    }
}
